package org.example.cake.service.impl;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.example.cake.mapper.UserdiscountMapper;
import org.example.cake.entity.Userdiscount;
import org.example.cake.service.UserdiscountService;

import java.util.List;

@Service
public class UserdiscountServiceImpl implements UserdiscountService{

    @Resource
    private UserdiscountMapper userdiscountMapper;

    @Override
    public int deleteByPrimaryKey(Integer userdiscount) {
        return userdiscountMapper.deleteByPrimaryKey(userdiscount);
    }

    @Override
    public int insert(Userdiscount record) {
        return userdiscountMapper.insert(record);
    }

    @Override
    public int insertSelective(Userdiscount record) {
        return userdiscountMapper.insertSelective(record);
    }

    @Override
    public Userdiscount selectByPrimaryKey(Integer userdiscount) {
        return userdiscountMapper.selectByPrimaryKey(userdiscount);
    }

    @Override
    public int updateByPrimaryKeySelective(Userdiscount record) {
        return userdiscountMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Userdiscount record) {
        return userdiscountMapper.updateByPrimaryKey(record);
    }


    /**
     * 根据用户id查询此用户有多少张优惠券
     * @param userid 用户id
     * @return 返回的个数
     */
    public int countByuserid(@Param("userid") Integer userid){
        return userdiscountMapper.countByuserid(userid);
    }
    /**
     * 修改优惠券状态
     * @Date 2025-08-04 谭丽那
     * @param userdiscount 用户连接优惠券
     * @return
     */
    @Override
    public Integer deldis(Userdiscount userdiscount) {
        return userdiscountMapper.updateQuanStatus(userdiscount);
    }

    /**
     * 批量新增优惠券
     * @param userdiscounts 用户优惠券对象
     */
    public void batchInsertDiscount(@Param("userdiscounts") List<Userdiscount> userdiscounts){
        userdiscountMapper.batchInsertDiscount(userdiscounts);
    }
    /**
     * 判断该用户是否拥有此优惠券 避免重复领取
     * @param userdiscount
     * @return
     */
    @Override
    public Integer getUsercountifTrue(Userdiscount userdiscount) {
        return userdiscountMapper.getUsercountifTrue(userdiscount);
    }
    /**
     * 新增用户优惠券
     * @param userdiscount
     * @return
     */
    @Override
    public Integer addfestOne(Userdiscount userdiscount) {
        return userdiscountMapper.insert(userdiscount);
    }
}
